﻿using MachinaAurum.DempsterShafer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace MachinaAurum.DempsterShaferTests
{
    [TestClass]
    public class DempsterShaferAerospaceIdentifiction
    {
        [TestMethod]
        public void Test()
        {
            var engine = new DempsterShaferEngine();
            engine.AddState(0, "AviãoComercial");
            engine.AddState(1, "Bombardeiro");
            engine.AddState(2, "Caça");

            engine.Start();

            Assert.AreEqual(8, engine.PowerSetValues.Count());
            Assert.AreEqual(8, engine.PowerSetLabels.Count());

            var evidence1 = engine.AddEvidences();
            evidence1.SetMass(0.7, 1, 2);
            evidence1.SetMass(0.3);
            engine.Accept(evidence1);

            var evidence2 = engine.AddEvidences();
            evidence2.SetMass(0.9, 1);
            evidence2.SetMass(0.1);
            engine.Accept(evidence2);

            Assert.AreEqual(0.90, engine.GetCurrentBeliefIn(1));
            Assert.AreEqual(0.97, engine.GetCurrentBeliefIn(1, 2));
            Assert.AreEqual(0.03, engine.GetCurrentBeliefIn());

            Assert.AreEqual(1.0, engine.GetCurrentPlausabilityIn(1));
            Assert.AreEqual(1.0, engine.GetCurrentPlausabilityIn(1, 2));

            Assert.AreEqual(0.0, engine.GetCurrentDoubtIn(1));
            Assert.AreEqual(0.0, engine.GetCurrentDoubtIn(1, 2));

            Assert.AreEqual(0.10, engine.GetCurrentIgnoranceIn(1), 0.001);
            Assert.AreEqual(0.03, engine.GetCurrentIgnoranceIn(1, 2), 0.001);

            var evidence3 = engine.AddEvidences();
            evidence3.SetMass(0.95, 0);
            evidence3.SetMass(0.05);
            engine.Accept(evidence3);

            Assert.AreEqual(0.363, engine.GetCurrentBeliefIn(0), 0.001);
            Assert.AreEqual(0.573, engine.GetCurrentBeliefIn(1), 0.001);
            Assert.AreEqual(0.363, engine.GetCurrentBeliefIn(0, 2), 0.001);
            Assert.AreEqual(0.363, engine.GetCurrentDoubtIn(1), 0.001);
            Assert.AreEqual(0.064, engine.GetCurrentIgnoranceIn(1), 0.001);
        }
    }
}
